#include <iostream>


class Fruit  //抽象产品
{
public:
    virtual void show() = 0;
};

class NorthPear : public Fruit
{
public:
    void show()
    {
        std::cout << "北方梨" << std::endl;
    }
};

class SouthPear : public Fruit
{
public:
    void show()
    {
        std::cout << "南方梨" << std::endl;
    }
};

class NorthApple : public Fruit
{
public:
    void show()
    {
        std::cout << "北方苹果" << std::endl;
    }
};

class SouthApple : public Fruit
{
public:
    void show()
    {
        std::cout << "南方苹果" << std::endl;
    }
};

class Factory  //抽象工厂类
{
public:
    virtual Fruit *CreateApple() = 0;  //产品族
    virtual Fruit *CreatePear() = 0;
};

class NorthFactory : public Factory  //北方工厂
{
public:
    virtual Fruit *CreateApple()
    {
        return new NorthApple;
    }
    virtual Fruit *CreatePear()
    {
        return new NorthPear;
    }
};

class SouthFactory : public Factory  //南方工厂
{
public:
    virtual Fruit *CreateApple()
    {
        return new SouthApple;
    }
    virtual Fruit *CreatePear()
    {
        return new SouthPear;
    }
};

int main()
{
    Factory *f = new NorthFactory;
    Fruit *a = f->CreateApple();
    a->show();
    return 0;
}